﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonClasses
{
    public abstract class Game
    {
        public abstract void Deal();
        //Deck myDeck = new Deck();

        //Hand player = new Hand();
        //Hand dealer = new Hand();
        
        //public frmBlackjack()
        //{   
            
        //    InitializeComponent();

            
        //    myDeck.initialize_cards();
        //}

        //private void clear_total_count()
        //{
        //    txtDealerCardCount.Clear();
        //    txtPlayerCardCount.Clear();
        //}

        //private void newgame_focus()
        //{
        //    btnNewGame.Enabled = true;
        //    btnNewGame.Focus();
        //}               

        //private void display_card(Hand playing_hand, GroupBox group_box)
        //{
        //    int x = 0;
        //    foreach (Card each_card in playing_hand.cards_on_hand)
        //    {
        //        foreach (PictureBox pb in group_box.Controls.OfType<PictureBox>())
        //        {                   
        //            if (pb.Name.EndsWith((x + 1).ToString()))
        //            {                        
        //                if (each_card.FaceDown == false)
        //                {
        //                    pb.ImageLocation = each_card.Image;
        //                }
        //                else
        //                {
        //                    pb.ImageLocation = each_card.FDImage;
        //                }                        
        //                break;
        //            }                
        //        }
        //        x++;                
        //    }
        //}

        //private void clear_picture_boxes()
        //{
        //    List<GroupBox> all_grb = new List<GroupBox>();
        //    all_grb.Add(grbDealerCards);
        //    all_grb.Add(grbPlayerCards);

        //    foreach (GroupBox gb in all_grb)
        //    {
        //        foreach (PictureBox pb in gb.Controls.OfType<PictureBox>())
        //        {
        //            pb.ImageLocation = null;
        //        }
        //    }
        //}

        //private void btnNewGame_Click(object sender, EventArgs e)
        //{
        //    clear_total_count();

        //    clear_picture_boxes();
        //    btnHitMe.Enabled = true;
        //    btnStand.Enabled = true;                

        //    if (myDeck.cards.Count < 10)
        //    {
        //        myDeck.initialize_cards();
        //        game_counter = 1;
        //    }

        //    txtGameRound.Text = game_counter.ToString();
        //    game_counter++;

        //    player = new Hand();
        //    dealer = new Hand();

        //    player.get_card(2, myDeck);
        //    display_card(player, grbPlayerCards);

        //    dealer.get_card(2, myDeck);
        //    dealer.cards_on_hand[1].FaceDown = true;
        //    display_card(dealer, grbDealerCards);

        //    player.calculate_total();
        //    txtPlayerCardCount.Text = player.total_count.ToString();

        //    dealer.calculate_total();
        //    //txtDealerCardCount.Text = dealer.total_count.ToString();

        //    txtCardsLeft.Text = myDeck.cards.Count().ToString();            

        //    btnNewGame.Enabled = false;
            
            
        //}

        //private void btnHitMe_Click(object sender, EventArgs e)
        //{
        //    if (player.cards_on_hand.Count() != player.max_num_cards)
        //    {
        //        player.get_card(1, myDeck);
        //        display_card(player, grbPlayerCards);

        //        player.calculate_total();
        //        txtPlayerCardCount.Text = player.total_count.ToString();

        //        txtCardsLeft.Text = myDeck.cards.Count().ToString();                
        //    }
        //    else
        //    {
        //        btnHitMe.Enabled = false;
        //        MessageBox.Show("You already have 5 cards.", "Card Limit Warning");
        //    }            
        //}

        //private void btnStand_Click(object sender, EventArgs e)
        //{
        //    string msgbox_title = "Winner";

        //    btnHitMe.Enabled = false;
        //    btnStand.Enabled = false;

        //    if (dealer.total_count >= 17)
        //    {
        //        foreach (Card c in dealer.cards_on_hand)
        //        {
        //            c.FaceDown = false;
        //        }
        //        display_card(dealer, grbDealerCards);

        //        //dealer.calculate_total();
        //        txtDealerCardCount.Text = dealer.total_count.ToString();
        //    }

        //    // Dealer get card logic.
        //    while (dealer.total_count < 17)
        //    {
        //        dealer.get_card(1, myDeck);
        //        foreach (Card c in dealer.cards_on_hand)
        //        {
        //            c.FaceDown = false;
        //        }
        //        display_card(dealer, grbDealerCards);

        //        dealer.calculate_total();
        //        txtDealerCardCount.Text = dealer.total_count.ToString();
        //    }         

        //    // Game winner logic.
        //    if ((dealer.total_count < 22) && (player.total_count < 22))
        //    {
        //        if (player.total_count > dealer.total_count)
        //        {
        //            if (player.total_count == 21)
        //            {
        //                MessageBox.Show("Blackjack: Player Wins!", msgbox_title);
        //            }
        //            else
        //            {
        //                MessageBox.Show("Player Wins!", msgbox_title);
        //            }                    
        //            newgame_focus();
        //        }
        //        else if (player.total_count < dealer.total_count)
        //        {
        //            if (dealer.total_count == 21)
        //            {
        //                MessageBox.Show("Blackjack: Dealer Wins!", msgbox_title);
        //            }
        //            else
        //            {
        //                MessageBox.Show("Dealer Wins!", msgbox_title);
        //            }                    
        //            newgame_focus();
        //        }
        //        else if ((dealer.total_count == 21) && (player.total_count == 21))
        //        {
        //            MessageBox.Show("Blackjack tie. Dealer wins!", msgbox_title);
        //            newgame_focus();
        //        }
        //        else
        //        {
        //            MessageBox.Show("Tie: Dealer Wins!", msgbox_title);
        //            newgame_focus();
        //        }
        //    }
        //    else if (player.total_count > 21)  // If player goes above 21, dealer wins regardless of dealer's hand.
        //    {
        //        MessageBox.Show("Player busted: Dealer Wins!", msgbox_title);
        //        newgame_focus();
        //    }
        //    else  // dealer's total count > 21. 
        //    {
        //        MessageBox.Show("Dealer busted: Player Wins!", msgbox_title);
        //        newgame_focus();
        //    }
            
        public abstract void Evaluate();

        public virtual void PlayerMove()
        {

        }

        public virtual void NewGame()
        {

        }

    }
}
